import HomePage from "./pages/HomePage.vue"
import ProfilePage from "./pages/ProfilePage.vue"
import ProfileEdittingPage from "./pages/ProfileEdittingPage.vue"
import LoginPage from "./pages/LoginPage.vue"
/*import loginStatus from "./pages/LoginPage.vue"*/
import ResetPasswdPage from "./pages/ResetPasswdPage.vue"
import { createRouter, createWebHistory } from "vue-router";

const routes = [
  {
    path: "/",
    name: "home",
    component: HomePage,
    alias: '/home',
    meta: {
      title: "藏头诗生成器",
      keepalive: true,
    }
  },
  {
    path: "/profile",
    name: "profile",
    component: ProfilePage,
    meta: {
      title: "个人主页",
      keepalive: true,
    }
  },
  {
    path: "/profile/edit",
    name: "profileEdit",
    component: ProfileEdittingPage,
    meta: {
      title: "编辑信息",
      keepalive: true,
    }
  },
  {
    path: "/login",
    name: "login",
    component: LoginPage,
    props: true,
    meta: {
      title: "登录",
      keepalive: true,
    }
  },
  {
    path: "/login/reset_password",
    name: "resetPw",
    component: ResetPasswdPage,
    meta: {
      title: "重置密码",
      keepalive: true,
    }
  },
  {
    path: "/:notFound(.*)/*", //使用$route.params.notFound访问匹配内容
    redirect: "/notFound"
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes: routes,
});


/*router.beforeEach(to => {
  if (to.name !== "login" && !loginStatus) {
    return {name: "login"};
  }
  if (to.name === "login" && loginStatus) {
    return {name: "home"};
  }
})*/


router.afterEach((to) => {
  document.title = to.meta.title;
})

export { router };